<template>
	<view class="dropdown">
		<view class="content">
			<view class="topSelect">
				<view class="left">
					<view class="item" v-for="(item,index) in dataOptions" :key="index"
						@click="handleClickAction(item,index)">
						<text>{{item.title}}</text>
						<!-- arrow-up-fill arrow-down-fill -->
						<u-icon :name="item.upDown?'arrow-down-fill':'arrow-up-fill'" color="#CCC" size="14"></u-icon>
					</view>
				</view>
				<view class="right">
					共<text>23</text>条
				</view>
			</view>
		</view>
		<view class="content-list" v-if="showSearch">
			<view>
				<view class="title">
					{{actionLabel}}
				</view>
				<view class="item-list">
					<view class="item active" @click="handleClickUnlimited">{{unlimitedName}}</view>
				</view>
				<view class="item-list">
					<view class="item" v-for="(item,index) in options" :key="index"
						@click="handleClickItem(item,index)">
						{{item.label}}
					</view>
				</view>
			</view>
			<view class="buttons">
				<view class="reset" @click="handleClickReset">{{resetName}}</view>
				<view class="submit" @click="handleClickSubmit">{{submitName}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "dropdown",
		props: {
			data: {
				type: Array,
				default: () => []
			},
			actionColor: {
				type: String,
				default: () => "#45D4A8"
			},
			resetName: {
				type: String,
				default: () => "重置"
			},
			submitName: {
				type: String,
				default: () => "确定"
			},
			unlimitedName: {
				type: String,
				default: () => "不限"
			},
			showSearch: {
				type: Boolean,
				default: false
			}
		},
		watch: {
			data: {
				handler(newData) {
					this.dataOptions = newData;
					this.dataOptions = newData.map(item => ({
						...item,
						upDown: false
					}));
				},
				immediate: true,
				deep: true
			}
		},
		data() {
			return {
				// upDown: true,
				actionLabel: "职业",
				dataOptions: [],
				options: [{
						label: '默认排序',
						value: 1,
					},
					{
						label: '距离优先',
						value: 2,
					},
					{
						label: '价格优先',
						value: 3,
					}
				]
			}
		},
		methods: {
			handleClickAction(item, index) { // 点击分类
				item.upDown = !item.upDown;
				console.log(item, index, "点击分类");
			},
			handleClickReset() { // 点击重置

			},
			handleClickSubmit() { // 点击确定

			},
			handleClickUnlimited() { // 点击不限

			},
			handleClickItem(item, index) { // 点击选项
				console.log(item, index, "点击选项");
			}
		},
		computed: {

		}
	}
</script>

<style lang="scss" scoped>
	.dropdown {
		position: inherit;

		.content {
			height: 42rpx;
			display: flex;
			column-gap: 48rpx;

			.topSelect {
				display: flex;
				align-items: center;
				justify-content: space-between;
				width: 100%;

				.left {
					display: flex;
					align-items: center;

					.item {
						display: flex;
						align-items: center;
						margin-right: 40rpx;

						>text {
							margin-right: 4rpx;
							font-size: 28rpx;
							font-weight: 400;
							color: rgba(102, 102, 102, 1);
						}
					}
				}

				.right {
					font-size: 12px;
					font-weight: 400;
					line-height: 17.38px;
					color: rgba(153, 153, 153, 1);
				}
			}
		}

		.content-list {
			position: relative;
			background-color: #FFF;
			border-radius: 16rpx;
			overflow: hidden;
			padding-top: 32rpx;
			margin-top: 56rpx;

			.title {
				font-size: 28rpx;
				font-weight: bold;
				color: rgba(51, 51, 51, 1);
			}

			.item-list {
				display: flex;
				gap: 16rpx;
				margin-top: 24rpx;

				.item {
					display: flex;
					justify-content: center;
					align-items: center;
					height: 64rpx;
					width: calc((100% - 32rpx) /3);
					font-size: 28rpx;
					font-weight: 400;
					color: rgba(94, 103, 110, 1);
					border-radius: 8rpx;
					background: rgba(246, 248, 252, 1);
				}

				.item.active {
					font-size: 28rpx;
					font-weight: 500;
					color: $theme-color;
					background-color: #EBF7F2;
				}
			}

			.buttons {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-top: 32rpx;

				>view {

					display: flex;
					justify-content: center;
					align-items: center;
					height: 80rpx;
					width: calc((100% - 16rpx) /2);
					border-radius: 8rpx;
					background: rgba(246, 248, 252, 1);
				}

				.reset {
					font-size: 28rpx;
					font-weight: 400;
					color: rgba(54, 68, 79, 1);
				}

				.submit {
					font-size: 28rpx;
					font-weight: 400;
					color: rgba(255, 255, 255, 1);
					background: $theme-color;
				}
			}

		}
	}
</style>